# -*- coding: utf-8 -*-

from django.db import models
from sm.models import CorpInfo
from pm.models import PersonInfo
from datetime import datetime
# Create your models here.
class Insur(models.Model):
    insur_type = models.CharField(max_length=2,primary_key=True) #险种类型
    insur_name = models.CharField(max_length=30) #险种名称

    def __str__(self):
        strings = self.insur_type+ " , "+ self.insur_name
        return strings
    
class Zjq(models.Model):
    zjq = models.DateField(primary_key=True)
    def __str__(self):
        strings = str(self.zjq.year)+" -- "+str(self.zjq.month)
        return strings
    
class PersonRecord(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    person = models.ForeignKey(PersonInfo,on_delete=models.CASCADE) #人员
    time_stamp = models.DateTimeField(auto_now=True)  # 日期戳
    oper_type = models.CharField(max_length=2) # 操作类型
    change = models.IntegerField()  #改变 增+1, 减-1
    p_st_a = models.CharField(max_length=2) #变动前状态
    p_st_b = models.CharField(max_length=2) #变动后状态
    dwbm_a = models.CharField(max_length=4) #变动前单位
    dwbm_b = models.CharField(max_length=4) #变动后状态
    user = models.CharField(max_length=20) #操作员
    chg_reason = models.CharField(max_length=50) #变动原因
    undo_flag = models.BooleanField() #撤销标志

    def __str__(self):
        strings = str(self.zjq)+" , "+self.person.scbh+ " , " \
                  + self.chg_reason+" , "+self.dwbm_b
        return strings

class PersonPay(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    person = models.ForeignKey(PersonInfo,on_delete=models.CASCADE) #人员
    person_cost = models.DecimalField(max_digits=10,decimal_places=2) #个人缴纳
    corp2person_cost = models.DecimalField(max_digits=10,decimal_places=2) #单位划入个人账户
    person_tax = models.DecimalField(max_digits=10,decimal_places=2) #个人交税

    def __str__(self):
        strings = str(self.zjq)+" , "+self.insur_type+" , "+self.person.name+" , " \
                  + self.person.scbh
        return strings
    
class CorpPay(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur_type = models.CharField(max_length=2) #险种类型
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    corp_cost = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    corp_rate = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    corp_salary = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳基数
    corp_tax = models.DecimalField(max_digits=10,decimal_places=2) #单位交税

    def __str__(self):
        strings = str(self.zjq)+" , "+self.insur_type+ " , "+self.corp.dwbm
        return strings
    



class Ratio(models.Model):
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    person_rate = models.DecimalField(max_digits=5,decimal_places=4,default=0)
    corp_rate = models.DecimalField(max_digits=5,decimal_places=4,default=0)
    corp2person_rate = models.DecimalField(max_digits=5,decimal_places=4,default=0)
    person_tax_rate = models.DecimalField(max_digits=5,decimal_places=4,default=0)
    corp_tax_rate = models.DecimalField(max_digits=5,decimal_places=4,default=0)

    def __str__(self):
        strings = self.corp.dwbm+" , "+self.insur.insur_name
        return strings
    
class PreCollect(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    corp_cost = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_cost = models.DecimalField(max_digits=20,decimal_places=2) #个人缴纳
    tax_pre = models.DecimalField(max_digits=20,decimal_places=2)#交税
    marks = models.CharField(max_length=60)#备注

    def __str__(self):
        pass
    
    
class PreNotice(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    corp_cost = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_cost = models.DecimalField(max_digits=20,decimal_places=2) #个人缴纳
    tax_pre = models.DecimalField(max_digits=20,decimal_places=2)
    corp_sup = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_sup = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    tax_sup = models.DecimalField(max_digits=20,decimal_places=2)
    person_rate = models.DecimalField(max_digits=5,decimal_places=4)
    corp_rate = models.DecimalField(max_digits=5,decimal_places=4)
    corp2person_rate = models.DecimalField(max_digits=5,decimal_places=4)
    person_tax_rate = models.DecimalField(max_digits=5,decimal_places=4)
    marks = models.CharField(max_length=60)

class ActCollect(models.Model):
    zzjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    corp_bucks = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_bucks = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    tax_act = models.DecimalField(max_digits=20,decimal_places=2)
    marks = models.CharField(max_length=60)

class SuppleCollect(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    dwbm = models.CharField(max_length=4) #单位编码(外键)
    flag_bt = models.BooleanField()
    sup_begin = models.DateField()
    sup_end = models.DateField()
    scbh = models.CharField(max_length=11)
    corp_sup = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_sup = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    tax_sup = models.DecimalField(max_digits=20,decimal_places=2)
    marks = models.CharField(max_length=60)

class OverdueCollect(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    corp_ovd = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_ovd = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    tax_ovd_total = models.DecimalField(max_digits=20,decimal_places=2)
    corp_ovd_total = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_ovd_total = models.DecimalField(max_digits=20,decimal_places=2) #单位缴费比例
    tax_ovd = models.DecimalField(max_digits=20,decimal_places=2)
    marks = models.CharField(max_length=60)


class ActNotice(models.Model):
    zjq = models.ForeignKey(Zjq,on_delete=models.CASCADE)
    insur = models.ForeignKey(Insur,on_delete=models.CASCADE) #险种类型
    corp = models.ForeignKey(CorpInfo,on_delete=models.CASCADE) #单位编码(外键)
    corp_bucks = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_bucks = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    tax_act = models.DecimalField(max_digits=20,decimal_places=2)
    marks = models.CharField(max_length=60)
    corp_ovd = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_ovd = models.DecimalField(max_digits=5,decimal_places=4) #单位缴费比例
    tax_ovd_total = models.DecimalField(max_digits=20,decimal_places=2)
    corp_ovd_total = models.DecimalField(max_digits=20,decimal_places=2) #单位缴纳
    person_ovd_total = models.DecimalField(max_digits=20,decimal_places=2) #单位缴费比例
    tax_ovd = models.DecimalField(max_digits=20,decimal_places=2)
    marks = models.CharField(max_length=60)
    




    
    
